package ioc

import (
	"gitee.com/xiao_hange/go-admin-pkg/pkg/redisx"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/redis/go-redis/v9"
	"github.com/spf13/viper"
)

func InitRedis() redis.Cmdable {
	addr := viper.GetString("redis.addr")
	pwd := viper.GetString("redis.pwd")
	redisClient := redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: pwd,
	})
	//prometheus
	redisClient.AddHook(redisx.NewPrometheusHook(
		prometheus.SummaryOpts{
			Namespace: "SunXQ",
			Subsystem: "GoAdmin",
			Name:      "Redis",
			Help:      "统计 Redis 的 HTTP 接口",
			Objectives: map[float64]float64{
				0.5:   0.01,
				0.9:   0.01,
				0.99:  0.005,
				0.999: 0.0001,
			},
		}))
	redisClient.AddHook(redisx.NewOpenTelemetryHook())
	return redisClient
}
